package com.cskaoyan.wordmemorize.auth;

import cn.dev33.satoken.stp.StpInterface;
import com.cskaoyan.wordmemorize.dao.mapper.UserMapper;
import com.cskaoyan.wordmemorize.dto.app.UserDTO;
import com.cskaoyan.wordmemorize.service.EmployeeService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Component
public class StpInterfaceImpl implements StpInterface {
    @Autowired
    EmployeeService employeeService;
    @Autowired
    UserMapper userMapper;

    /*
         只需要自己实现这个方法即可
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        if ("admin".equals(loginType)) {
            Set<String> permissionAlias = employeeService.getPermissionAlias(Long.valueOf((String) loginId));
            List<String> strings = new ArrayList<>();
            boolean b = strings.addAll(permissionAlias);
            return strings;
        }else if("user".equals(loginType)){
            // TODO 获取前端账户的等级 (privilege_code)权限列表
            Set<String> allPrivilegeCode = userMapper.getAllPrivilegeCode(Long.valueOf((String) loginId));
            List<String> strings = new ArrayList<>();
            boolean b = strings.addAll(allPrivilegeCode);
            return strings;
        }
        return null;
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return null;
    }
}
